package com.zxx.admin.config.auth.security;//package com.zxx.config.auth.security;
//
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.zxx.entity.sys.SysAdminEntity;
//import com.zxx.entity.sys.SysRoleEntity;
//import com.zxx.service.sys.SysAdminService;
//import com.zxx.service.sys.SysRoleService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Service
//public class SecurityUserDetailsService implements UserDetailsService {
//
//    @Autowired
//    private SysAdminService adminService;
//
//    @Autowired
//    private SysRoleService roleService;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//
//        QueryWrapper<SysAdminEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("user_name", username);
//        SysAdminEntity admin = adminService.getOne(queryWrapper);
//
//        if (admin == null) {
//            throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
//        } else {
//            //查询出角色信息封装到admin中
//            List<String> roleNames = new ArrayList<>();
//            SysRoleEntity role = roleService.getById(admin.getRoleUid());
//            roleNames.add(role.getRoleName());
//
//            admin.setRoleNames(roleNames);
//
//            return SecurityUserFactory.create(admin);
//        }
//    }
//}
